package com.plugin.manage.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.plugin.manage.pojo.dto.ElderAssessmentInfoDTO;
import com.plugin.manage.pojo.vo.ElderAssessmentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 老人评估信息Mapper
 *
 * @author mark
 * @date 2025-08-01
 */
@Mapper
public interface ElderAssessmentMapper {

    /**
     * 三表联查获取老人评估信息（分页）
     * elder_info, elder_assessment, elder_check_in 三表联查
     */
    @Select("SELECT " +
            "ea.id AS id, " +
            "ei.realname AS realname, " +
            "ei.age AS age, " +
            "ea.assessor_name AS assessorName, " +
            "ea.assessment_date AS assessmentDate, " +
            "ea.ability_level AS abilityLevel, " +
            "ea.care_level AS careLevel, " +
            "ea.psychological_status AS psychologicalStatus, " +
            "ea.assessment_result AS assessmentResult, " +
            "ea.remark AS remark, " +
            "ea.status AS assessmentStatus, " +
            "eci.status AS checkInStatus " +
            "FROM elder_info ei " +
            "INNER JOIN elder_check_in eci ON ei.elder_id = eci.elder_id " +
            "INNER JOIN elder_assessment ea ON eci.assess_id = ea.id AND eci.elder_id = ea.elder_id " +
            "WHERE eci.is_leave = 0 AND ei.del = 0 " +
            "ORDER BY ea.assessment_date DESC")
    IPage<ElderAssessmentInfoDTO> getElderAssessmentInfo(IPage<ElderAssessmentInfoDTO> page);
    
    /**
     * 获取长者评估详细信息
     * 
     * @return 长者评估信息VO
     */
    @Select("SELECT " +
            "ei.realname, " +
            "ei.age, " +
            "ei.phone, " +
            "ea.status, " +
            "ea.assessment_date AS assessmentDate, " +
            "ea.assessor_name AS assessorName, " +
            "ea.care_level AS careLevel, " +
            "ea.physical_status AS physicalStatus, " +
            "ea.cognitive_status AS cognitiveStatus, " +
            "ea.remark " +
            "FROM elder_info ei " +
            "INNER JOIN elder_assessment ea ON ei.elder_id = ea.elder_id " +
            "WHERE ei.del = 0 AND ea.del = 0 " +
            "ORDER BY ea.assessment_date DESC")
    ElderAssessmentVO getElderAssessmentDetail();
}
